import sys
from kmeans import *
import numpy as np
import Image
from scipy.spatial.distance import cdist

def histogram(codebook,points):
    # codebook and pixelist are list of array (from numpy) of integer
    k = len(codebook)
    if(k<2):
        return
    
    centroids = np.array(codebook)
    
    hist = np.zeros((k,)) # array inicial zerado com os valores do histograma
    
    distances_to_codewords = cdist(points, centroids, 'euclidean')
    selected = np.argmin(distances_to_codewords, axis=1)
    
    for i in range(k):
        hist[i] = np.where(selected==i)[0].size
        
    return hist
    
    
codebook_path = sys.argv[1]
cbfile = open(codebook_path)
codebooklst = read_points(cbfile)
cbfile.close()

img = Image.open(sys.stdin)
pixelist = img.getdata()

hist = histogram(codebooklst,pixelist)

sys.stdout.write(" ".join(str(int(x)) for x in hist)+"\n")



    
    